<!doctype html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
  <meta name="generator" content="Hugo 0.88.1">
  <!-- 解决ajax被spring security的CSRF拦截POST和PUT请求问题 -->
  <meta name="_csrf" th:content="${_csrf.token}">
  <meta name="_csrf_header" th:content="${_csrf.headerName}">
  <title>签到</title>

  <!-- Bootstrap core CSS -->
  <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
  <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
  <style>
    @media (min-width: 768px) {
      #un {
        color: var(--light);
        font-size: 1.1rem;
      }

      .sign {
        background: #f3f4f6;
      }

      #main div div div {
        background: white;
      }
    }

  </style>
  <!-- Custom styles for this template -->
  <link th:href="@{/css/dashboard.css}" rel="stylesheet">
  <link th:href="@{/css/toastr.min.css}" rel="stylesheet">

</head>
<body onload="app()">

<div th:replace="~{common :: top-nav}"></div>

<div class="container-fluid">
  <div class="row">
    <!--左侧导航-->
    <div class="col-2">
      <div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
        <a class="nav-link" id="v-pills-home-tab" role="tab" aria-selected="true" th:href="@{/login/main}" sec:authorize="hasAnyRole('STUDENT','GUARD','MG','TESTER')">个人信息</a>
        <a class="nav-link" id="v-pills-profile-tab" role="tab" aria-selected="false" th:href="@{/access/info(id=${session.user.id})}" sec:authorize="hasRole('STUDENT')">出入记录</a>
        <a class="nav-link" id="v-pills-result-tab" role="tab" aria-selected="false" th:href="@{/detected/findResultByNo(id=${session.user.id})}" sec:authorize="hasRole('STUDENT')">核酸检测结果信息</a>
        <a class="nav-link active" id="v-pills-sign-ed" role="tab" aria-selected="false" th:href="@{/stu/sign-formation}" sec:authorize="hasRole('STUDENT')">签到信息</a>
      </div>
    </div>
    <!-- 签到 -->
    <div class="col-10 divider" id="main">
      <div class="tab-pane fade show active" role="tabpanel" sec:authorize="hasAnyRole('STUDENT')">
        <div class="row justify-content-center py-2">
          <div class="col-md-10 col-sm-10" id="MyMessage" style="display: none">
            <h4 class="mb-3">
              学生健康上报
            </h4>
            <hr class="mb-1"/>
            <small>为了避免新型冠状病毒在学校内传播，请各位如实填写！</small>
            <form class="needs-validation" th:action="@{/security/sign}" method="post" novalidate>
              <!-- 体温 -->
              <div class="form-group mb-3 pt-2">
                <label class="h6"><span class="text-primary">*01. </span>今天你的体温时多少？</label>
                <div class="custom-control custom-radio">
                  <input class="custom-control-input sig-input" type="radio" name="tw" id="zc" value="37.2度及以下"
                         required>
                  <label class="custom-control-label" for="zc">37.2度及以下</label>
                </div>
                <div class="custom-control custom-radio">
                  <input class="custom-control-input sig-input" type="radio" name="tw" id="fs" value="37.3度-37.9度"
                         required>
                  <label class="custom-control-label" for="fs">37.3度-37.9度</label>
                </div>
                <div class="custom-control custom-radio">
                  <input class="custom-control-input sig-input" type="radio" name="tw" id="fgs" value="38度以上"
                         required>
                  <label class="custom-control-label" for="fgs">38度以上</label>
                </div>
              </div>
              <!-- 身体健康状态 -->
              <div class="form-group mb-3 pt-2">
                <label class="h6"><span class="text-primary">*02. </span>今天你的身体状况是？</label>
                <div class="custom-control custom-radio">
                  <input class="custom-control-input sig-input" type="radio" name="bd" id="bd-jk" value="健康"
                         required>
                  <label class="custom-control-label" for="bd-jk">健康</label>
                </div>
                <div class="custom-control custom-radio">
                  <input class="custom-control-input sig-input" type="radio" name="bd" id="bd-fs" value="发烧"
                         required>
                  <label class="custom-control-label" for="bd-fs">发烧</label>
                </div>
                <div class="custom-control custom-radio">
                  <input class="custom-control-input sig-input" type="radio" name="bd" id="bd-fl" value="乏力"
                         required>
                  <label class="custom-control-label" for="bd-fl">乏力</label>
                </div>
                <div class="custom-control custom-radio">
                  <input class="custom-control-input sig-input" type="radio" name="bd" id="bd-gk" value="干咳"
                         required>
                  <label class="custom-control-label" for="bd-gk">干咳</label>
                </div>
                <div class="custom-control custom-radio">
                  <input class="custom-control-input sig-input" type="radio" name="bd" id="bd-other" value="其他"
                         required>
                  <label class="custom-control-label" for="bd-other">其他</label>
                </div>
              </div>
              <!-- 共同居主人接触史1 -->
              <div class="form-group mb-3 pt-2">
                <label class="h6"><span
                        class="text-primary">*03. </span>近14天你的共同居主人是否有疫情中、高风险区域人员接触史？</label>
                <div class="custom-control custom-radio">
                  <input class="custom-control-input sig-input" type="radio" name="jc" id="u-yes" value="1"
                         required>
                  <label class="custom-control-label" for="u-yes">是</label>
                </div>
                <div class="custom-control custom-radio">
                  <input class="custom-control-input sig-input" type="radio" name="jc" id="u-no" value="0"
                         required>
                  <label class="custom-control-label sig-input" for="u-no">否</label>
                </div>
              </div>
              <!-- 共同居主人接触史2 -->
              <div class="form-group mb-3 pt-2">
                <label class="h6"><span
                        class="text-primary">*04. </span>近14天你的共同居主人是否和确诊、疑似病人接触过？</label>
                <div class="custom-control custom-radio">
                  <input class="custom-control-input sig-input" type="radio" name="jc2" id="u4-yes" value="1"
                         required>
                  <label class="custom-control-label" for="u4-yes">是</label>
                </div>
                <div class="custom-control custom-radio">
                  <input class="custom-control-input sig-input" type="radio" name="jc2" id="u4-no" value="0"
                         required>
                  <label class="custom-control-label" for="u4-no">否</label>
                </div>
              </div>
              <!-- 是否属实 -->
              <div class="form-group mb-3 pt-2">
                <label class="h6"><span class="text-primary">*05. </span>本人是否承若以上所填报的全部内容均属实、准确，不存在任何隐瞒与不实的情况、更无遗漏之处？</label>
                <div class="custom-control custom-radio">
                  <input class="custom-control-input sig-input" type="radio" name="ss" id="u5-yes" value="1" required>
                  <label class="custom-control-label" for="u5-yes">是</label>
                </div>
                <div class="custom-control custom-radio">
                  <input class="custom-control-input sig-input" type="radio" name="ss" id="u5-no" value="0" required>
                  <label class="custom-control-label" for="u5-no">否</label>
                </div>
              </div>
              <!-- 位置 -->
              <div class="form-group mb-3 pt-2">
                <label class="h6"><span class="text-primary">*06. </span>所在位置</label>
                <div class="pr-5">
                  <button type="button" class="btn btn-block text-left sign sig-input" onclick="address()">
                    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
                         fill="currentColor" class="bi bi-geo-alt-fill" viewBox="0 0 16 16">
                      <path d="M8 16s6-5.686 6-10A6 6 0 0 0 2 6c0 4.314 6 10 6 10zm0-7a3 3 0 1 1 0-6 3 3 0 0 1 0 6z"/>
                    </svg>
                    <span id="addressText"></span>
                    <input id="addressInput" type="hidden" value="" name="add">
                  </button>
                </div>
              </div>
              <!-- 内容有误 -->
              <hr class="mb-2"/>
              <div class="form-group mb-3 pt-2 text-center">
                <span class="text-black-50">内容有误？</span>
                <a th:href="@{/stu/sign-in}" class="text-decoration-none">重新填写</a>
              </div>
              <div class="form-group px-5">
                <input type="hidden" name="sno" th:value="${session.user.no}">
                <button type="submit" class="btn btn-primary btn-block" disabled>已提交</button>
              </div>
            </form>
          </div>
          <div class="col-md-6 col-sm-6" style="display: none" id="div-sign-ing">
            <div class="row gx-lg-5">
              <!-- 未上报 -->
              <div class="col-lg-8 mb-4">
                <div class="icon-demo mb-4 rounded-3 d-flex align-items-center justify-content-center p-3 py-5"
                     style="font-size: 5em" role="img" aria-label="Check circle fill - large preview">
                  <svg xmlns="http://www.w3.org/2000/svg" width="150" height="150" fill="currentColor"
                       color="#fac664" class="bi bi-x-circle-fill" viewBox="0 0 16 16">
                    <path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM5.354 4.646a.5.5 0 1 0-.708.708L7.293 8l-2.647 2.646a.5.5 0 0 0 .708.708L8 8.707l2.646 2.647a.5.5 0 0 0 .708-.708L8.707 8l2.647-2.646a.5.5 0 0 0-.708-.708L8 7.293 5.354 4.646z"/>
                  </svg>
                </div>
                <div class="rounded-3 d-flex align-items-center justify-content-center p-3">
                  <label class="h4">未健康上报</label>
                </div>
                <div class="rounded-3 d-flex align-items-center justify-content-center p-3">
                  <a th:href="@{/stu/sign-in}" class="page-link text-primary">现在去上报</a>
                </div>

              </div>
            </div>
            <input type="hidden" id="success-msg" th:value="${param.success}">
            <input type="hidden" id="error-msg" th:value="${param.error}">
          </div>
        </div>

      </div>
    </div>
  </div>
</div>

<script src="https://code.jquery.com/jquery-3.4.1.min.js"
        integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
        crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script th:src="@{/js/jquery.slim.min.js}"><\/script>')</script>
<script th:src="@{/js/bootstrap.bundle.min.js}"></script>
<script src="https://webapi.amap.com/maps?v=1.4.10&key=ccc557b111dd155750089e029fe3126e&plugin=AMap.AdvancedInfoWindow"></script>

<script src="https://cdn.jsdelivr.net/npm/feather-icons@4.28.0/dist/feather.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js"></script>
<script th:src="@{/js/user-info.js}"></script>
<script th:src="@{/js/dashboard.js}"></script>
<script th:src="@{/js/toastr.min.js}"></script>
<script th:src="@{/js/form-validation.js}"></script>
</body>
<script type="text/javascript" th:inline="javascript">
  var token = $("meta[name='_csrf']").attr("content");
  var header = $("meta[name='_csrf_header']").attr("content");
  $(document).ajaxSend(function (e, xhr, options) {
    xhr.setRequestHeader(header, token);
  })

  function signE() {
    $(".sig-input").attr("disabled","disabled");
    $("#div-sign-ing").hide();
    $("#MyMessage").hide();
    var stuno = $('#sno').val();
    $.ajax({
      url: "/security/find",
      type: "get",
      dataType: "json",
      data: {"sno": stuno},
      success: function (res) {
        if (res.status) {
          let info = JSON.parse(res.value)
          $("input[name='tw'][value='" + info.tw + "']").prop("checked","checked");
          $("input[name='bd'][value='" + info.bd + "']").prop("checked","checked");
          $("input[name='jc'][value='" + Number(info.jc) + "']").prop("checked","checked");
          $("input[name='jc2'][value='" + Number(info.jcs) + "']").prop("checked","checked");
          $("input[name='ss'][value='" + Number(info.cn) + "']").prop("checked","checked");
          $("#addressText").text(info.address);
          $("#MyMessage").show();
        }else{
          $("#div-sign-ing").show();
        }
      }
    })

  }

  function isEmpty(v) {
    switch (typeof v) {
      case 'undefined':
        return true;
      case 'string':
        if (v.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '').length == 0) return true;
        break;
      case 'boolean':
        if (!v) return true;
        break;
      case 'number':
        if (0 === v || isNaN(v)) return true;
        break;
      case 'object':
        if (null === v || v.length === 0) return true;
        for (var i in v) {
          return false;
        }
        return true;
    }
    return false;
  }

  function msg() {
    toastr.options.positionClass = 'toast-top-center';
    var errMsg = $('#error-msg').val();
    var succMsg = $('#success-msg').val();
    if (!isEmpty(succMsg)) {
      toastr.success('' + succMsg, '提示')
    } else if (!isEmpty(errMsg)) {
      toastr.error('' + errMsg, '错误')
    }
    return false
  }

  function app() {
    msg()
    findSign()
    signE()
  }
</script>
</html>
